//
//  dengluViewController.m
//  企业信息查询
//
//  Created by 梁中豪 on 16/4/7.
//  Copyright © 2016年 梁中豪. All rights reserved.
//

#import "dengluViewController.h"
#import "meTableViewController.h"
#import "ViewController.h"
#import <BmobSDK/Bmob.h>

@interface dengluViewController ()

- (IBAction)cancel:(id)sender;
- (IBAction)wjmm:(id)sender;

  //cancel按钮关闭模态操作
- (IBAction)textFiledReturnEditing:(id)sender; //按下return关闭键盘方法
- (IBAction)backgroundTap:(id)sender; //点击背景关闭键盘
- (IBAction)zhanghaoDL:(id)sender;
@end

@implementation dengluViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)textFiledReturnEditing:(id)sender {
    [sender resignFirstResponder];
}

- (IBAction)backgroundTap:(id)sender {
    [_zhanghao resignFirstResponder];
    [_mima2 resignFirstResponder];
}




- (IBAction)zhanghaoDL:(id)sender {
    [BmobUser loginWithUsernameInBackground:_zhanghao.text
                                   password:_mima2.text
                                      block:^(BmobUser *user,NSError *error){
                                          if (user) {
                                              NSLog(@"%@",user);
                                              
                                              
                                              [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeNameNotification" object:self userInfo:@{@"name":self.zhanghao.text}];
                                              
                                              UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                                              UINavigationController *secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"shouyeboard2"];
                                              [self.navigationController pushViewController:secondViewController animated:YES];
                                              
                                              [self dismissViewControllerAnimated:YES completion:nil];
                                         }
                                          else {
                                              NSLog(@"%@",error);
                                              //初始化提示框；
                                              UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码错误" preferredStyle:  UIAlertControllerStyleAlert];
                                              
                                              [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                                  //点击按钮的响应事件,这里不用相应 直接提示密码错误  ；
                                              }]];
                                              
                                              //弹出提示框；
                                              [self presentViewController:alert animated:true completion:nil];
                                              
                                          }
                                      }];
}
- (IBAction)cancel:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)wjmm:(id)sender {
    //[BmobUser requestPasswordResetInBackgroundWithEmail:@"77249084@qq.com"];

}
@end
